var customerModel;
var rowData = [];

function getRowData(){
	return rowData;
}

function checkAllotNumber(postdata){
	//页面添加页数限制，查询最多1w天数据;判定时，超过2000，则不允许调配
	$.ajax({
		 url:'/customerManage/queryCustomerNumber',
		 async:false,
		 contentType:'application/x-www-form-urlencoded;charset=UTF-8',
		 type:'post',
         dataType:'json',
		 data:postdata,
		 beforeSend:function(){},
		 success:function(ret){
			console.log(ret);
			$("#allotNum").val(ret.status);
			customerModel = ret.currentCustomer;
			rowData = ret.customerIds;
			
		}
		}); 
	
}

function setCompany(company){
	if(company==null){
		company = customerModel;
	}
	//设置当前分公司id，name
	var companyNow = $("#companyNow");
	companyNow.text(company.companyAbb);
	var compamyid = $("#compamyid");
	compamyid.val(company.companyId);
}

function setCompanyId(compamyid,companyNow){
	//设置当前分公司id，name
	var label = $("#companyNow");
	label.text(companyNow);
	var id = $("#compamyid");
	id.val(compamyid);
}

function findDept(){
	var url = "/authority/department/getDeptByString";
	$.post(
			url,
			{},
			function(data) {
				var expressCompany = $("#receivedCompany");
				expressCompany.empty(); 
				  var str = '';
				  for(var o in data) {
				str += '<option value="'+data[o].companyIdStr.split(",")[0]+','+data[o].id+'">'+data[o].dname+'</option>';
				}
				  expressCompany.append(str);
				//刷新selectpicker重新加载上面循环append部分的内容
				  $('#receivedCompany.selectpicker').selectpicker('refresh');
			}
			
	);
	
}

function setReceivedPerson(value){
	var data = value.split(",");
	var url = "/authority/employee/getEmpListByDeptIdStr";
	$.post(
			url,
			{deptIdStr:data[1]},
			function(data) {
				var expressCompany1 = $("#receivedPerson");
				expressCompany1.empty(); 
				  var str = '';
				  for(var o in data) {
				str += '<option value="'+data[o].empno+'">'+data[o].ename+'</option>';
				}
				  expressCompany1.append(str);
				  $('#receivedPerson.selectpicker').selectpicker('refresh');
			}
			);
}
//根据分公司是否是当前分公司来显示隐藏员工下拉框
function setReceivedPersonShow(value){
	var data = value.split(",");
	var compamyid = $("#compamyid").val();
	 
	if(data[0]==compamyid){
		$('#receivedPerson.selectpicker').selectpicker('show');
	}else{
		$('#receivedPerson.selectpicker').selectpicker('hide');
		var expressCompany1 = $("#receivedPerson");
		expressCompany1.empty();
		$('#receivedPerson.selectpicker').selectpicker('refresh');
	}
}

function clearSelect(){
	var expressCompany1 = $("#receivedPerson");
	expressCompany1.empty();
	$('#receivedPerson.selectpicker').selectpicker('refresh');
	var expressCompany = $("#receivedCompany");
	expressCompany.empty(); 
	$('#expressCompany.selectpicker').selectpicker('refresh');
}

//查询消耗预估
function query(pageNow) {
	checkcusId();
	
	controllerWaitingBar(true);
	//获取项目上下文路径
	rootPath = $('#rootPath').val();
	
	//获取当前页的下一页/上一页
	if(!pageNow) {
		pageNow = 1;
	}else if(pageNow == "nextPage") {
		pageNow = $('#pageNow').val();
		var pageCount = $('#pageCount').html();
		//如果当前页是最后一页 则下一页无效
		if(pageNow == pageCount) {
			controllerWaitingBar(false);
			return ;
		}
		pageNow = $('#pageNow').val()*1 + 1;
	}else if(pageNow == "prevPage") {
		pageNow = $('#pageNow').val();
		//如果当前页是第一页 则上一页无效
		if(pageNow == "1") {
			controllerWaitingBar(false);
			return ;
		}
		pageNow = $('#pageNow').val()*1 - 1;
	}else if(pageNow == "lastPage") {
		pageNow = $('#pageCount').html();
	}
	
	var customId = $('#customId').val();
	var empId = $('#emp').val();
	var regionalId = $('#area').val();
	var startTime = $('#startTime').val();
	var endTime = $('#endTime').val();
	var consumePhase = $('#consumePhase').val();
	var businessType = $('#businessType').val();
	var consumeState = $('#consumeState').val();
	var product = $('#productCode').val();
	if(!checkForm()) {
		return ;
	}
	var url = rootPath + "/serviceManage/queryfindxiao";
	$.post(
		url,
		{
			"cusId": customId,
			"empId": empId,
			"regionalId": regionalId,
			"startTime": startTime,
			"endTime": endTime,
			"consumePhase":consumePhase,
			"businessType":businessType,
			"state":consumeState,
			"product": product,
			"pageNow": pageNow
		},
		function(data) {
			var json = eval(data);
			if(5 == json) {
				location.href = rootPath + "/login/loginPage";
				return ;
			}
			var html = "";
			html += '<tr>';
	        html += '<th>交易编号</th>';
	        html += '<th>交易日期</th>';
	        html += '<th>资金流动</th>';
	        html += '<th>类型</th>';
	        html += '<th>产品</th>';
	        html += '<th>账户余额</th>';
	        html += '</tr>'; 
	       
	        var isResponsible = $('#isResponsible').val();
	        var userId = $('#userId').val();
	        if(json.length == 0) {
				html += '<tr><td colspan="15">没有查到相关数据！</td></tr>';
			}else {
				
				for(var i=0; i<json.length; i++) {
					var money = 0;
					var orderlineType = '';
					if(json[i].increase==null){
						money = json[i].decrease;
					}else{
						money = json[i].increase;
					}
					
					if(json[i].orderLineType=='N'){
						orderlineType = '消费';
					}else if(json[i].orderLineType=='C'){
						orderlineType = '充值';
					}else{
						orderlineType = '消费';
					}
					
					html += '<td>' + json[i].accountDetailCode + '</td>';
					html += '<td>' + json[i].operateTime + '</td>';
					html += '<td>' + money + '</td>';
					
					html += '<td>' + orderlineType + '</td>';
					html += '<td>' + json[i].goodsName + '</td>';
					html += '<td>' + json[i].balance + '</td>';
					html += '  </td>';
					html += '</tr>';
				} 
			}
			$('#dataList').html(html);
			
			//显示分页
			if(json.length) {
				var pageNow = json[0].pageNow;
				var pageSize = json[0].pageSize;
				var rowCount = json[0].rowCount;
				var pageCount = json[0].pageCount;
				
				$('#pageNow').val(pageNow);
				$('#pageSize').html("1-" + pageSize);
				$('#rowCount').html(rowCount);
				$('#pageIndex').html(pageNow);
				$('#pageCount').html(pageCount);
			}else {
				$('#pageNow').val("1");
				$('#pageSize').html("1-20");
				$('#rowCount').html("0");
				$('#pageIndex').html("1");
				$('#pageCount').html("1");
			}
			controllerWaitingBar(false);
		}
	);
}

function toExport(){
	
	form.submit();
}

function getContextPathTemp() {
	var result=$("#rootPath").val();
    return result;
}

function checkcusId(){
	var cusid = $("#customId").val();
	if(cusid==null||cusid==""){
		alert("请填写会员编号！");
		return false;
	}
}


